import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/publicBussine/bussine_colors.dart';
import 'package:honeypotflutter/publicBussine/bussine_date.dart';
import 'package:honeypotflutter/publicBussine/view/bussine_button.dart';
import 'logic.dart';

class CabinetFormBottomMonthPage extends StatefulWidget {
  final Function(String start, String end)? result;
  const CabinetFormBottomMonthPage({
    Key? key,
    this.result,
  }) : super(key: key);

  @override
  State<CabinetFormBottomMonthPage> createState() => _CabinetFormBottomMonthPageState();
}

class _CabinetFormBottomMonthPageState extends State<CabinetFormBottomMonthPage> {
  final CabinetFormBottomMonthLogic logic = Get.put(CabinetFormBottomMonthLogic());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: MGColors.whileColor,
      body: Flex(
        direction: Axis.horizontal,
        children: [
          Expanded(
              child: Container(
            height: 250,
            child: CupertinoPicker(
              itemExtent: 50.0, // 每个条目的高度
              onSelectedItemChanged: (index) {
                // 当选中的条目发生变化时的回调
                logic.selectMonth(index);
              },
              children: logic.yearList.map((e) => Center(child: Text(e.toString()))).toList(),
            ),
          )),
          Expanded(
              child: GetBuilder<CabinetFormBottomMonthLogic>(
                  id: "month",
                  builder: (controller) {
                    return Container(
                      height: 250,
                      child: CupertinoPicker(
                        itemExtent: 50.0, // 每个条目的高度
                        onSelectedItemChanged: (index) {
                          // 当选中的条目发生变化时的回调
                          controller.month = index + 1;
                        },
                        children: logic.monthList.map((e) => Text(e.toString())).toList(),
                      ),
                    );
                  }))
        ],
      ),
      bottomNavigationBar: MGButton(
        title: "确认",
        backColor: MGColors.whileColor,
        margin: EdgeInsets.only(left: 20, right: 20, bottom: 40),
        buttonAction: () {
          if (widget.result != null) {
            BussineSelectDateModel date = MGBussineDate.calculateDate(yy: logic.year, mm: logic.month);
            widget.result!(date.startTime, date.endTime);
          }
          Get.back();
        },
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<CabinetFormBottomMonthLogic>();
    super.dispose();
  }
}
